<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Widget extends OC_Controller {

	function __construct()
	{
		parent::__construct();
		$this->load->model('widget/widget_model','wm');
		$this->load->model('widget/category_model','cm');
	}

	function _remap($method, $params = array())
	{
		parent::_remap($method, $params);
		
		if (method_exists($this, $method))
			return call_user_func_array(array($this, $method), $params);
		else
			show_404();
	}

	function init_header()
	{
		$this->header['jeasyui'] 	= TRUE;
		$this->header['categories'] = $this->cm->get_all()->rows;
		$this->header['source_bot'] = array(
			script_tag(site_url('widget/themescript/moment.js')),
			script_tag(site_url('widget/themescript/app/widget.js'))
		);
	}

	function index()
	{
		$this->init_header();
		$this->header['nav'] = 'widget';
		$this->header['pagetitle'] = 'Widget';
		$this->view('widget/widget_view');
	}

	function load_data()
	{
		$params = $this->input->post();
		$result = $this->wm->get_all($params);
		print(json_encode($result));
	}

	function save_data()
	{
		$post = $this->input->post();
		
		if (empty($post['widget_id'])) {
			$post['widget_created_date'] = date('Y-m-d H:i:s');
			unset($post['widget_id']);
			$this->wm->add($post);
		} else {
			$post['widget_modified_date'] = date('Y-m-d H:i:s');
			$this->wm->edit($post, array(
				'widget_id' => $post['widget_id']
			));
		}
		
		print(json_encode(array(
			'success' => TRUE
		)));
	}

	function delete_data()
	{
		$post = $this->input->post();
		$this->wm->delete(array('widget_id' => $post['widget_id']));
		print(json_encode(array(
			'success' => TRUE
		)));
	}

}

/* End of file widget.php */
/* Location: .//D/OemahCode/hann/module_admin/widget/controllers/widget.php */